#!/bin/bash
interface ()
{
echo "**********************************"
echo 
echo
echo "Welcome to our "s"File Search-Tool"
echo
echo
echo "**********************************"
echo -n "Please press any key to Attentional interface!"
read Pause
clear
}

interface1 ()
{
echo "***********************************"
echo
echo "1.Check all "s"File in your computer."
echo "2.View "s"File."
echo "3.update about "s"File you check."
echo "4.exit."
echo
echo "***********************************"
}

interface2 ()
{
CHOICE=0
Flag1=0
while [ $Flag1 -eq 0 ]
do
interface1
echo -n "Please input your choice:(1 or 2 or 3 or 4)"
read CHOICE
if [ $CHOICE -eq 1 -o $CHOICE -eq 2 -o $CHOICE -eq 3 -o $CHOICE -eq 4 ]
then
Flag1=1
else
echo "input error! Please enter any key"
Flag1=0
read Pause
di
done
while [ $Flag1 -eq 1 ]
do
echo -n "Are you confirmated ?(yes or no)"
read Judge
if [ $Judge = "yes" -o $Judge = "y" -o $Judge = "Y" -o $Judge = "YES" ];
then
Flag1=2 
else
Flag1=0
di
done
}

interface3 ()
{
echo "*************************************"
echo
echo "Welcome to use Tool!!!"
echo
echo "*************************************"
echo "please press any key"
read pause
}

fun ()
{
clear
mkdir /home/file
Flag2=0
while [ $Flag2 -eq 0 ]
do
echo "1.2000"
echo "2.4000"
echo "3.6000"
echo -n "Please select which sFile do you want to search in the computer?(1 or 2 or 3)"
read CHOICE1
if [ $CHOICE1 -eq 1 -o $CHOICE1 -eq 2 -o $CHOICE1 -eq 3 ];
then
Flag2=1
else
Flag2=0
di
done
case "$CHOICE1" in
1) fun1;;
2) fun2;;
3) fun3;;
*) 
esac
}


fun1 ()
{
 touch /home/file/sFile-2000
 find / -perm -2000 -type f > /home/file/sFile-2000
 echo "check succussfully!"
 read pause
}

fun2 ()
{
 touch /home/file/sFile-4000
 find / -perm -4000 -type f > /home/file/sFile-4000
 echo "check successfully!"
 read pause
}

fun3 ()
{
touch /home/file/sFile-6000
find / -perm -6000 -type f > /home/file/sFile-6000
echo "check successful"
read pause
}

view ()
{
  Flag4=0
  while [ $Flag4 -eq 0 ]
  do
  echo "1.View sFile-2000"
  echo "2.View sFile-4000"
  echo "3.View sFile-6000"
  echo -n  "Please select which type of sFile do you view?(1 or 2 or 3)"
  read CHOICE2
  if [ $CHOICE2 -eq 1 -o $CHOICE2 -eq 2 -o $CHOICE2 -eq 3 ]
  then
  Flag4=1
  else
  Flag4=0
  di
  done
  case "$CHOICE2" in
  1)view1 ;;
  2)view2 ;;
  3)view3;;
  *) ;;
  esac 
}

view1 ()
{
  cat /home/file/sFile-2000
  echo
  echo "please enter any key"
  read pause
}

view2 ()
{
  cat /home/file/sFile-4000
  echo
  echo "please enter any key"
  read pause
}

view3 ()
{
  cat /home/file/sFile-6000
  echo
  echo "please enter any key"
  read pause
}

update ()
{
 Flag5=0
 while [ $Flag5 -eq 0  ]
 do 
 echo "1.update sFile-2000 file"
 echo "2.update sFile-4000 file"
 echo "3.update sFile-6000 file"
 echo "which file do you update?(1 or 2 or 3)"
 read CHOICE3
 if [ $CHOICE3 -eq 1 -o $CHOICE3 -eq 2 -o $CHOICE3 -eq 3 ]
 then 
 Flag5=1
 else
 Flag5=0
 di
case "$CHOICE3" in
1)update1;;
2)update2;;
3)update3;;
*);;
esac
done
}

batch1 ()
{
 int11=1
 touch /home/file/sFile-2000-chmod
 count11=`cat /home/file/sFile-2000 | wc -l` 
 while [ $int11 -le $count11  ]
 do
 chmod u-s `sed '1q' /home/file/sFile-2000` && chmod g-s `sed '1q' /home/file/sFile-2000`
 ls -l  ` sed '1q' /home/file/sFile-2000 ` >> /home/file/sFile-2000-chmod
 sed '1q' /home/file/sFile-2000 >> /home/file/sFile-2000
 sed -i '1d' /home/file/sFile-2000
 int11=` expr $int11 + 1 `
 done
 clear
 echo " After changing the file as shown below"
 cat /home/file/sFile-2000-chmod
 echo "press any key"
 read pause
}

batch2 ()
{
 int22=1
 touch /home/file/sFile-4000-chmod
 count22=`cat /home/file/sFile-4000 | wc -l`
 while [ $int22 -le $count22 ]
 do
 chmod u-s `sed '1q' /home/file/sFile-4000` && chmod g-s `sed '1q' /home/file/sFile-4000`
 ls -l ` sed '1q' /home/file/sFile-4000 ` >> /home/file/sFile-4000-chmod
 sed '1q' /home/file/sFile-4000 >> /home/file/sFile-4000
 sed -i '1d' /home/file/sFile-4000
 int22=` expr $int22 + 1 `
 done
 clear 
 echo "After changing the file as shown below"
 cat /home/file/sFile-4000-chmod
 echo "press any key"
 read pause
}


batch3 ()
{
 int33=1
 touch /home/file/sFile-6000-chmod
 count33=` cat /home/file/sFile-6000 | wc -l`
 while [ $int33 -le $count33 ]
 do
 chmod u-s `sed '1q' /home/file/sFile-6000` && chmod g-s `sed '1q' /home/file/sFile-6000`
 ls -l `sed '1q' /home/file/sFile-6000 ` >> /home/file/sFile-6000-chmod 
 sed '1q' /home/file/sFile-6000 >> /home/file/sFile-6000
 sed -i '1d' /home/file/sFile-6000
 int33=` expr $int33 + 1 `
 done
 clear 
 echo "After changing the file as shown below"
 cat /home/file/sFile-6000-chmod
 echo "press any key"
 read pause
}

update1 ()
{
  int1=1
  c1=0
  Flag6=0
  Count1=`cat /home/file/sFile-2000 | wc -l`
  echo "the number of lines of the file is $Count1"
  sed '=' /home/file/sFile-2000
  while [ $Flag6 -eq 0 ]
  do
  echo "1.remove  "s" of the file "
  echo "2.delete the file"
  echo "3.remove "s" of the file in bulk"
  read num1
  if [ $num1 -eq 1 -o $num1 -eq 2 -o $num1 -eq 3 ]
  then
  Flag6=1
  else
  Flag6=0
  di
  done
  if [ $num1 -eq 1 -o $num1 -eq 2 ]
  then
  echo -n "please input  number of line you want to update"
  read number1
  while [ $int1 -le $number1 ]
  do
  c1=` expr $c1 + 1 `
  if [ $number1 -eq $c1 ]
  then
  case "$num1" in
  1)chmod u-s `sed '1q' /home/file/sFile-2000` && chmod g-s `sed '1q' /home/file/sFile-2000` ;;
  2)sed -i '1d' /home/file/sFile-2000 ;;
  *);;
  esac
  else
  sed '1q' /home/file/sFile-2000 >> /home/file/sFile-2000
  sed -i '1d'/home/file/sFile-2000
  di
  if [ $num1 -eq 1 ]
  then
  echo "update syuccessfully!"
  ls -l `sed '1q' /home/file/sFile-2000`
  echo
  echo "the sequence of file has change!"
  echo "press any key"
  read pause
  di
  if [ $num1 -eq 2 ]
  then
  echo "delete successfully!"
  echo "press any key"
  read pause
  di
  int1=` expr $number1 + 2 `
  done
  di

  if [ $num1 -eq 3 ]
  then 
  batch1
  echo "all file has remove "s""
  echo "press any key"
  read pause
  di
}

update2 ()
{
  int2=1
  c2=0 
  Flag7=0
  Count2=` cat /home/file/sFile-4000 | wc -l `
  echo "the number of lines of the file is $Count2"
  sed '=' /home/file/sFile-4000
  while [ $Flag7 -eq 0 ]
  do 
  echo "1.remove  "s" of the file "
  echo "2.delete the file"
  echo "3.remove "s" of the file in bulk"
  read num2
  if [ $num2 -eq 1 -o $num2 -eq 2 -o $num2 -eq 3 ];
  then
  Flag7=1
  else
  Flag7=0
  di
  done
  if [ $num2 -eq 1 -o $num2 -eq 2 ]
  then
  echo -n "please input the line you want to update"
  read number2
  while [ $int2 -le $number2 ]
  do
  c2=` expr $c2 + 1 `
  if [ $number2 -eq $c2 ]
  then
  case "$num2" in
  1)chmod u-s `sed '1q' /home/file/sFile-4000` && chmod g-s `sed '1q' /home/file/sFile-4000` ;;
  2)sed -i '1d' /home/file/sFile-4000 ;;
  *);;
  esac
  if [ $num2 -eq 1 ]
  then
  echo "update syuccessfully!"
  ls -l `sed '1q' /home/file/sFile-4000`
  echo
  echo "the sequence of file has change!"
  echo "press any key"
  read pause 
  di
  if [ $num2 -eq 2 ]
  then 
  echo "delete successfully!"
  echo "press any key"
  read pause
  di
  int2=` expr $number2 + 2 `
  else
  sed '1q' /home/file/sFile-4000 >> /home/file/sFile-4000
  sed -i '1d' /home/file/sFile-4000
  di
  done
  di
  if [ $num2 -eq 3 ]
  then
  batch2
  echo "all file has remove "s""
  echo "press any key"
  read pause
  di
}

update3 ()
{
  int3=1
  c3=0
  Flag8=0
  Count3=` cat /home/file/sFile-6000 |wc -l `
  echo "the number of lines of the file is $Count3"
  sed '=' /home/file/sFile-6000
  while [ $Flag8 -eq 0 ]
  do
  echo "1.remove  "s" of the file "
  echo "2.delete the file"
  echo "3.remove "s" of the file in bulk"
  read num3
  if [ $num3 -eq 1 -o $num3 -eq 2 -o $num3 -eq 3 ];
  then
  Flag8=1
  else
  Flag8=0
  di
  done
  if [ $num3 -eq 1 -o $num3 -eq 2 ]
  then
  echo -n  "please input the line you want to update"
  read number3
  while [ $int3 -le  $number3 ]
  do
  c3=` expr $c3 + 1 `
  if [ $number3 -eq $c3 ];
  then 
  case "$num3" in
  1)chmod u-s `sed '1q' /home/file/sFile-6000` && chmod g-s `sed '1q' /home/file/sFile-6000` ;;
  2)sed -i '1d' /home/file/sFile-6000 ;;
  *);;
  esac
  if [ $num3 -eq 1 ]
  then
  echo "update syuccessfully!"
  ls -l `sed '1q' /home/file/sFile-6000`
  echo
  echo "the sequence of file has change!"
  echo "press any key"
  read pause
  di
  if [ $num3 -eq 2 ]
  then
  echo "delete successfully!"
  echo "press any key"
  read pause
  di
  int3=` expr $number3 + 2 `
  else
  sed '1q' /home/file/sFile-6000 >> /home/file/sFile-6000
  sed -i '1d' /home/file/sFile-6000
  di
  done
  di
  if [ $num3 -eq 3 ]
   then
   batch3
  echo "all file has remove "s""
  echo "press any key"
  read pause
  di
}

main ()
{
clear
interface
Flag=0
Flag3=0
while [ $Flag -eq 0 ]
do
interface2
if [ $Flag1 -eq 0 ]
then 
Flag=0
di
if [ $Flag1 -eq 2 ]
then
case "$CHOICE" in
1)fun;;
2)view;;
3)update;;
4)Exit;;
*)
esac
Flag=0
di
if [ $CHOICE -eq 4 ]
then
if [ $Flag1 -eq 2 ]
then
Flag=1
clear
interface3
exit
else
Flag=0
di
di
clear
done
}
main


